package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.rejectreasonvo.RejectReasonCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.rejectreasonvo.RejectReasonPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.rejectreasonvo.RejectReasonRespVO;
import com.cmc.cloud.cmclink.doc.vo.rejectreasonvo.RejectReasonUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmes.framework.common.pojo.PageResult;

import com.cmc.cloud.cmclink.doc.entity.RejectReasonDO;
import com.cmc.cloud.cmclink.doc.service.RejectReasonService;


/**
 * {table.classComment}前端接口Controller
 * 
 * @author codegen
 */
@Tag(name = "管理后台 - 常用订舱拒绝理由")
@RestController
@RequestMapping(UrlConstants.APPLICATION_URL+"/reason")
@Validated
public class RejectReasonController {

    @Resource
    private RejectReasonService rejectReasonService;

    @Operation(summary = "创建常用订舱拒绝理由")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission('doc:maintainRejectReason:add')")
    public CommonResult<Void> createRejectReason(@Valid @RequestBody RejectReasonCreateReqVO createReqVO) {
        rejectReasonService.createRejectReason(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新常用订舱拒绝理由")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission({'doc:maintainRejectReason:edit','doc:maintainRejectReason:enable'})")
    public CommonResult<Void> updateRejectReason(@Valid @RequestBody RejectReasonUpdateReqVO updateReqVO) {
        rejectReasonService.updateRejectReason(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除常用订舱拒绝理由")
    @Parameter(name = "id", description = "编号", required = true)
    @PostMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermission('doc:maintainRejectReason:delete')")
    public CommonResult<Void> deleteRejectReason(@PathVariable("id") Long id) {
        rejectReasonService.deleteRejectReason(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得常用订舱拒绝理由")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @GetMapping("/getById/{id}")
    public CommonResult<RejectReasonRespVO> getRejectReason(@PathVariable("id") Long id) {
        RejectReasonDO rejectReason = rejectReasonService.getRejectReason(id);
        return CommonResult.success(BeanUtil.copyProperties(rejectReason, RejectReasonRespVO.class));
    }

    @Operation(summary = "获得常用订舱拒绝理由列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @GetMapping("/listAll")
    @PreAuthorize("@ss.hasPermission('doc:maintainRejectReason:search')")
    public CommonResult<List<RejectReasonRespVO>> getRejectReasonList() {
        List<RejectReasonDO> list = rejectReasonService.getRejectReasonList();
        return CommonResult.success(BeanUtil.copyToList(list,RejectReasonRespVO.class));
    }

    @Operation(summary = "获得常用订舱拒绝理由分页")
    @PostMapping("/getPage")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission('doc:maintainRejectReason:search')")
    public CommonResult<PageResult<RejectReasonRespVO>> getRejectReasonPage(@Valid @RequestBody RejectReasonPageReqVO pageVO) {
        PageResult<RejectReasonDO> pageResult = rejectReasonService.getRejectReasonPage(pageVO);
        List<RejectReasonRespVO> results = BeanUtil.copyToList(pageResult.getList(),RejectReasonRespVO.class);
        return CommonResult.success(new PageResult<>(results,pageResult.getTotal()));
    }
}
